#include "iobot.h"

void iobot_backspace(iobot_t *bot)
{
	if(bot->csr_x > 0)
	{
		bot->csr_x -= 1;
		bot->botout[(bot->csr_y * bot->textwidth) + bot->csr_x] = ' ';

		bot->dirty_x -= 1;
	}
	else
	{
		if(bot->csr_y > 0)
		{
			bot->csr_y -= 1;
			bot->csr_x = bot->textwidth - 1;
			bot->botout[(bot->csr_y * bot->textwidth) + bot->csr_x] = ' ';

			bot->dirty_y -= 1;
			bot->dirty_x = 0;
			bot->dirty_width = bot->textwidth;
		}
	}
}

void iobot_delete(iobot_t* bot)
{
	char* tmp = (char*)bot->botout + ((bot->csr_y * bot->textwidth) + bot->csr_x);
	while(*tmp != ' ')
	{
		*tmp = *(tmp + 1);
		tmp++;
	}
	bot->dirty_y = 0;
	bot->dirty_x = 0;
	bot->dirty_width = bot->textwidth + 1;
	bot->dirty_height = bot->textheight + 1;
	bot->dirty = 1;
}
